---

- name: keepalived-configure check user
  user:
    name: "{{ keepalived_scripts_user }}"
    shell: "/bin/bash"
    system: True
  become: True
  become_user: "root"
  tags: [keepalived, keepalived-configure]

- name: keepalived-configure check directory
  file:
    path: "{{ item.path }}"
    state: "directory"
    mode: "{{ item.mode }}"
    owner: "root"
    group: "root"
  become: True
  loop:
    - mode: "755"
      path: "{{ keepalived_scripts_path }}"
  tags: [keepalived, keepalived-configure]

- name: keepalived-configure check scripts
  template:
    src: "{{ item.source }}"
    dest: "{{ keepalived_scripts_path }}/{{ item.name }}"
    owner: "{{ keepalived_scripts_user }}"
    group: "{{ keepalived_scripts_user }}"
    mode: "755"
  become: True
  become_user: "root"
  loop: "{{ keepalived_scripts }}"
  tags: [keepalived, keepalived-configure]

- name: keepalived-configure check config
  template:
    src: "{{ keepalived_config_source }}"
    dest: "/etc/keepalived/keepalived.conf"
    owner: "root"
    group: "root"
    mode: "644"
  become: True
  become_user: "root"
  tags: [keepalived, keepalived-configure]

- name: keepalived-configure stop service
  systemd:
    name: "keepalived"
    state: "stopped"
    enabled: True
  become: True
  become_user: "root"
  tags: [never, keepalived-stop]

- name: keepalived-configure start service
  systemd:
    name: "keepalived"
    state: "started"
    enabled: True
  become: True
  become_user: "root"
  tags: [keepalived, keepalived-start]
